package com.have.blog.xo.service.admin.impl;

import com.have.blog.base.enums.BlogStatus;
import com.have.blog.model.mapper.TNetworkDiskMapper;
import com.have.blog.model.mapper.TStorageMapper;
import com.have.blog.model.models.TNetworkDisk;
import com.have.blog.model.models.TStorage;
import com.have.blog.model.models.TStorageExample;
import com.have.blog.utils.MyStringUtils;
import com.have.blog.utils.ResultUtils;
import com.have.blog.xo.constant.MessageConstant;
import com.have.blog.xo.service.admin.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.support.FeignUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
@SuppressWarnings("all")
public class StorageServiceImpl implements StorageService {
    @Autowired
    private TStorageMapper storageMapper;
    @Autowired
    private TNetworkDiskMapper networkDiskMapper;
    @Autowired
    private FeignUtils feignUtils;

    @Override
    public String initStorageSize(String adminUid, Long maxStorageSize) {
        TStorageExample example = new TStorageExample();
        example.createCriteria()
                .andAdminUidEqualTo(adminUid)
                .andStatusEqualTo(BlogStatus.ENABLE.getStatus());
        List<TStorage> tStorages = storageMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(tStorages)) {
            return ResultUtils.errorWithMessage(MessageConstant.ENTITY_EXIST);
        }

        TStorage saveStorage = new TStorage();
        saveStorage.setUid(MyStringUtils.getUUID());
        saveStorage.setAdminUid(adminUid);
        saveStorage.setStorageSize(0L);
        saveStorage.setMaxStorageSize(maxStorageSize);
        saveStorage.setStatus(BlogStatus.ENABLE.getStatus());
        storageMapper.insert(saveStorage);
        return ResultUtils.successWithMessage(MessageConstant.OPERATION_SUCCESS);
    }

    @Override
    public String editStorageSize(String adminUid, Long maxStorageSize) {

        return null;
    }

    @Override
    public List<TStorage> getStorageByAdminUid(List<String> adminUidList) {
        return null;
    }

    @Override
    public String uploadFile(TNetworkDisk networkDisk, List<MultipartFile> fileDatas) {
        return null;
    }

    @Override
    public TStorage getStorageByAdmin() {
        return null;
    }
}
